package com.informa.hamcrest.matchers;

import org.dom4j.Node;
import org.hamcrest.TypeSafeMatcher;
import org.hamcrest.Description;

import com.informa.utils.XmlUtils;



public class NodeXPathMatcher extends TypeSafeMatcher<Node> {

	private String xpath;
	
	public NodeXPathMatcher(String xpath) {
		this.xpath = xpath;
	}
	
	@Override
	public boolean matchesSafely(Node node) {
		return XmlUtils.exists(node, xpath);
	}

	public void describeTo(Description description) {
		description.appendText("Node does not match xpath " + xpath);
	}
	
	public static NodeXPathMatcher matchesXpath(String xpath) {
		return new NodeXPathMatcher(xpath);
	}
	
	
	
}
